import { GIRL_VIDEO_API, GIRL_IMAGE_API } from "./constants.js";

export const getGirlImage = async function () {
    try {
        const response = await fetch(GIRL_IMAGE_API);
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        const body = await response.json();
        console.log("body::", body, typeof body, body.url, body.code);

        return body.code == 200 ? body.url : null;
    } catch (error) {
        console.log(error);
        return null;
    }
}

export const getGirlVideo = function () {
    try {
        // 立即执行·
        (async () => {
            const response = await fetch(GIRL_VIDEO_API);
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            const body = await response.json();
            console.log("body::", body, typeof body, body.mp4_video, body.code);

            return body.code == 200 ? body.mp4_video : null;
        })();

    } catch (error) {
        console.log(error);
        return null;
    }
}
